package com.example.imtoken.modules.main.wallet.manage.wallet.add

import androidx.recyclerview.widget.LinearLayoutManager
import com.example.imtoken.R
import com.example.imtoken.core.base.BaseActivity
import com.example.imtoken.databinding.ActivityAddWalletBinding
import com.example.imtoken.modules.main.wallet.create.CreateWalletDialogFragment

class AddWalletActivity :
    BaseActivity<AddWalletViewModel, ActivityAddWalletBinding>(AddWalletViewModel::class.java) {

    private lateinit var adapter: AddWalletAdapter

    override fun initLayoutId(): Int {
        return R.layout.activity_add_wallet
    }

    override fun init() {
        dataBinding.include3.tvHeadTitles.text = getString(R.string.addWallet)
        dataBinding.include3.ivHeadBack.setOnClickListener {
            this.finish()
        }

        initAdapter()
        initObserve()
        viewModel.getCoinsData()
    }

    private fun initObserve() {
        viewModel.getCoinsLiveData().observe(this) {
            adapter.setList(it)
        }
    }

    private fun initAdapter() {
        adapter = AddWalletAdapter(R.layout.item_wallet_list)
        dataBinding.rvWalletList.layoutManager = LinearLayoutManager(this)
        dataBinding.rvWalletList.adapter = adapter
        adapter.setOnItemClickListener { _, _, position ->
            val dialog = CreateWalletDialogFragment(adapter.data[position].coin)
            dialog.show(supportFragmentManager, "dialog")
        }
    }

}